<?php

namespace app\home\controller\user;

use app\home\controller\HomeController;
use app\home\form\user\LoginRequest;
use Firebase\JWT\JWT;

class AuthController extends HomeController
{
    public function login(LoginRequest $request)
    {
        $user = $request->login();
        $key = config("app.jwt.secret");
        $payload = [
            'iss' => 'http://example.org',
            'aud' => 'http://example.com',
            'iat' => 1356999524,
            'nbf' => 1357000000,
            "uid" => $user->id
        ];
        return $this->ok([
            "token" => JWT::encode($payload, $key, 'HS256')
        ]);
    }
}